﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

public class DAL_tbl_psd_type
{
    public DAL_tbl_psd_type()
    {

    }



    public List<tbl_psd_type> select(int PSD_ID)
    {
        List<tbl_psd_type> list = new List<tbl_psd_type>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select PSD_ID,PSD_TYPE,IS_ACTIVE,CREATED_BY,CREATED_DATE,MODIFIED_BY,MDIFIED_DATE from tbl_psd_type where PSD_ID=@PSD_ID";
        cmd.Parameters.AddWithValue("@PSD_ID", PSD_ID);
        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_psd_type()
            {
                PSD_ID = Convert.ToInt32(dr["PSD_ID"]),
                PSD_TYPE = dr["PSD_TYPE"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                MODIFIED_BY = dr["MODIFIED_BY"].ToString(),
                MDIFIED_DATE = dr["MDIFIED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public List<tbl_psd_type> selectAll()
    {
        List<tbl_psd_type> list = new List<tbl_psd_type>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select PSD_ID,PSD_TYPE,IS_ACTIVE,CREATED_BY,CREATED_DATE,MODIFIED_BY,MDIFIED_DATE from tbl_psd_type Order By PSD_ID";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_psd_type()
            {
                PSD_ID = Convert.ToInt32(dr["PSD_ID"]),
                PSD_TYPE = dr["PSD_TYPE"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                MODIFIED_BY = dr["MODIFIED_BY"].ToString(),
                MDIFIED_DATE = dr["MDIFIED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public int insert(String PSD_TYPE, bool IS_ACTIVE, String CREATED_BY, DateTime CREATED_DATE)
    {
        int i = 0;
        string sql = @"Insert into tbl_psd_type(PSD_TYPE, IS_ACTIVE, CREATED_BY, CREATED_DATE)
                        values(@PSD_TYPE, @IS_ACTIVE, @CREATED_BY, @CREATED_DATE)";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@PSD_TYPE", PSD_TYPE);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@CREATED_BY", CREATED_BY);
        cmd.Parameters.AddWithValue("@CREATED_DATE", CREATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int update(int PSD_ID, String PSD_TYPE, bool IS_ACTIVE, String MODIFIED_BY, DateTime MDIFIED_DATE)
    {
        int i = 0;
        string sql = @"Update tbl_psd_type SET PSD_TYPE=@PSD_TYPE, IS_ACTIVE=@IS_ACTIVE, MODIFIED_BY=@MODIFIED_BY, MDIFIED_DATE=@MDIFIED_DATE WHERE PSD_ID=@PSD_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@PSD_ID", PSD_ID);
        cmd.Parameters.AddWithValue("@PSD_TYPE", PSD_TYPE);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@MODIFIED_BY", MODIFIED_BY);
        cmd.Parameters.AddWithValue("@MDIFIED_DATE", MDIFIED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int delete(int PSD_ID)
    {
        int i = 0;
        string sql = "Delete FROM tbl_psd_type WHERE PSD_ID=@PSD_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@PSD_ID", PSD_ID);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



}